<include file='Common:header' />
<link rel="stylesheet" type="text/css" media="all" href="__PUBLIC__/sldate/daterangepicker-bs3.css" />
<script type="text/javascript" src="__PUBLIC__/sldate/moment.js"></script>
<script type="text/javascript" src="__PUBLIC__/sldate/daterangepicker.js"></script>
<script src="__PUBLIC__/My97DatePicker/WdatePicker.js"></script>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

    <!-- #section:basics/sidebar -->

    <include file='Common:left' />
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">

                <!--主题-->
                <div class="page-header">
                    <h1>
                        您当前操作
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            选择汇总表
                        </small>
                    </h1>
                </div>





                <div class="row">
                    <div class="col-xs-12">
                        <div>
                            <form class="form-horizontal" name="form" id="form"  method="post"   action="{:U('create_table')}">
                                <div class="form-group">
                                    <label class="col-sm-5 control-label no-padding-right" for="form-field-1">选择汇总表：  </label>
                                    <div class="col-sm-7">
                                        <select name="tableid" id="tableid">
                                            <option value="">--选择报表--</option>
                                            <foreach name="list" item="v">
                                                <option value="{$v.id}">{$v.title}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="space-4"></div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">报表年份：  </label>
                                    <div class="col-sm-3">
                                            <select id="year" name="year">
                                                <option value="0">请选择年份</option>
                                                <volist name="year" id="v">
                                                    <option value="{$v}">{$v}</option>   
                                                </volist>
                                            </select>                                    </div>
                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-1">报表季度：  </label>
                                    <div class="col-sm-3">
                                        <select id="quarter" name="quarter">
                                            <option value="0">请选择季度</option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                        </select>                                    </div>
                                </div>
                                <div class="space-4"></div>

                                <div class="clearfix form-actions">
                                    <div class="col-md-offset-5 col-md-9">
                                        <button class="btn btn-info" type="submit" >
                                            <i class="ace-icon fa fa-check bigger-110"></i>
                                            生成
                                        </button>

                                        &nbsp; &nbsp; &nbsp;
                                        <button class="btn" type="reset">
                                            <i class="ace-icon fa fa-undo bigger-110"></i>
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

                <include file='Common:header_nav' />

            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->


    <script>

        function CheckAll(form){
            for (var i=0;i<form.elements.length;i++){
                var e = form.elements[i];
                if (e.Name != 'chkAll'&&e.disabled==false)
                    e.checked = form.chkAll.checked;
            }
        }

        function checkForm(){

            if( '' == $.trim($('#tableid option:selected').val())){
                layer.alert('请选择报表', {icon: 6}, function(index){
                    layer.close(index);
                    $('#tableid').focus();
                });
                return false;
            }


            if( '' == $.trim($('#year').val())){
                layer.alert('报表年份不能为空', {icon: 6}, function(index){
                    layer.close(index);
                    $('#year').focus();
                });
                return false;
            }
            //正则判断年份格式是否正确
            var reDateTime = /^(?:19|20)[0-9][0-9]$/;
            var isDateTime = reDateTime.test($.trim($('#year').val()));
            if (isDateTime == false){
                layer.alert('报表年份格式有误', {icon: 6}, function(index){
                    layer.close(index);
                    $('#year').focus();
                });
                return false;
            }


            if('' == $.trim($('#quarter').val())){
                layer.alert('报表季度不能为空', {icon: 6}, function(index){
                    layer.close(index);
                    $('#quarter').focus();
                });
                return false;
            }
            var quarter1 = $.trim($('#quarter').val());
            var arr = new Array("1","2","3","4");
            var isquarter = $.inArray(quarter1,arr);
            if(isquarter == -1){
                layer.alert('报表季度格式有误', {icon: 6}, function(index){
                    layer.close(index);
                    $('#quarter').focus();
                });
                return false;
            }

        }

        $(function(){

            $("form").submit(function () {
                return checkForm();
            })

            $('#form1').ajaxForm({
                beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
                success: complete, // 这是提交后的方法
                dataType: 'json'
            });


            function complete(data){
                if(data.status==1){
                    layer.alert(data.info, {icon: 6}, function(index){
                        layer.close(index);
                        window.location.href=data.url;
                    });
                }else{
                    layer.alert(data.info, {icon: 6}, function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }

        });
    </script>
    <include file='Common:footer' />

</div><!-- /.main-container -->
</body>
</html>
